<html>
<head>
	<title>easyCalculator</title>
	<style>
		td,th {border:1 maroon solid;}	
		input {font-size:35px;width:80px;height:50px;background-color:#DDDDDD;}
		.input1{width:360px;text-align:right;background-color:#EEEEEE;}
	</style>

	<script>
		var total = 0;
		var newFlag = true;
		var op = "";
		var tmp = 0;
		var complete = 0;

		function enterNumber(num){
			if(newFlag == true){
				complete++;
				tmp = parseFloat(num);
				document.myform.number.value = num;
				newFlag = false;
			}else{
				tmp = tmp * 10 + parseFloat(num);
				document.myform.number.value = tmp;
			}
		}

		function operate(opp){
			newFlag = true;
			if(opp == 'C'){
				clearAll();
			}else if(opp != '='){
				op = opp;
			}else{
				if(op == '+'){total = total + tmp;}
				if(op == '-'){total = total - tmp;}
				if(op == '*'){total = total * tmp;}
				if(op == '/'){total = total / tmp;}
				document.myform.number.value = total;
				complete = 0;
			}
			if(complete == 0)
				total = parseFloat(document.myform.number.value);
			else
				total = tmp;
		}

		function clearAll(){
			document.myform.number.value = 0;
			newFlag = true;
			total = 0;
			complete = 0;
			tmp = 0;
		}
	</script>
</head>

<body>
	<table align="center" width="360" cellpadding="5" cellspacing="0">
		<form name="myform" method="POST" action="">
		<tr>
			<td colspan="4"><input class="input1" type="text" name="number" value="0"></td>
		</tr> 
		<tr>
			<td><input type="button" name="number7" value="7" onClick="enterNumber(7)"></td>
			<td><input type="button" name="number8" value="8" onClick="enterNumber(8)"></td>
			<td><input type="button" name="number9" value="9" onClick="enterNumber(9)"></td>
			<td><input type="button" name="add" value="+" onClick="operate('+')"></td>
		</tr>
		<tr>
			<td><input type="button" name="number4" value="4" onClick="enterNumber(4)"></td>
			<td><input type="button" name="number5" value="5" onClick="enterNumber(5)"></td>
			<td><input type="button" name="number6" value="6" onClick="enterNumber(6)"></td>
			<td><input type="button" name="subtract" value="-" onClick="operate('-')"></td>
		</tr>
        <tr>
            <td><input type="button" name="number1" value="1" onClick="enterNumber(1)"></td>
            <td><input type="button" name="number2" value="2" onClick="enterNumber(2)"></td>
            <td><input type="button" name="number3" value="3" onClick="enterNumber(3)"></td>
            <td><input type="button" name="multiply" value="*" onClick="operate('*')"></td>		    
		</tr>
		<tr>
			<td><input type="button" name="number0" value="0" onClick="enterNumber(0)"></td>
			<td><input type="button" name="clear" value="C" onClick="operate('C')"></td>
			<td><input type="button" name="divide" value="/" onClick="operate('/')"></td>
			<td><input type="button" name="equal" value="=" onClick="operate('=')"></td>
		</tr> 
		</form>
	</table>
</body>	
</html>
